class SingletonUnsafeLazy {
    private static instance: SingletonUnsafeLazy;
    private constructor() { }

    public static getInstance(): SingletonUnsafeLazy {
        if (SingletonUnsafeLazy.instance == null) {
            SingletonUnsafeLazy.instance = new SingletonUnsafeLazy();
        }
        return SingletonUnsafeLazy.instance;
    }

    public showMessage() {
        console.log("Hello SingletonUnsafeLazy!");
    }
}
class SingletonUnsafeLazyTest {
    constructor() {

        //获取唯一可用的对象
        let object: SingletonUnsafeLazy = SingletonUnsafeLazy.getInstance();

        //显示消息
        object.showMessage();
    }
}
class SingletonSafeWaste {
    private static instance: SingletonSafeWaste = new SingletonSafeWaste();
    private constructor() { }
    public static getInstance(): SingletonSafeWaste {
        return SingletonSafeWaste.instance;
    }

    public showMessage() {
        console.log("Hello SingletonSafeWaste!");
    }
}
class SingletonSafeWasteTest {
    constructor() {
        let o: SingletonSafeWaste = SingletonSafeWaste.getInstance();
        o.showMessage();
    }
}


let test;
//test = new SingletonUnsafeLazyTest();
test = new SingletonSafeWasteTest();//推荐